package com.ynny.bookmanagersystem.dao;

import com.ynny.bookmanagersystem.base.BaseDAO;
import com.ynny.bookmanagersystem.entity.User;

import java.util.List;

public class UserDaoImpl extends BaseDAO<User> implements UserDao {
    @Override
    public List<User> selectAllUsers() {

        String sql = "select * from user";
        List<User> users = selectAll(sql);
        return users;
    }

    @Override
    public User selectUserById(Integer id) {

        String sql = "select * from user where id=?";
        User user = super.selectOne(sql, id);
        return user;
    }

    @Override
    public int insertUser(User user) {

        String sql = "insert into user(userName,password,name,age) values (?,?,?,?)";
        int i = insert(sql, user.getUserName(), user.getPassword(), user.getName(), user.getAge());
        return i;
    }

    @Override
    public int updateUser(User user) {
        String sql = "update user set userName = ?,password = ?,name = ?,age = ? where id = ?";

        int i = update(sql, user.getUserName(), user.getPassword(), user.getName(), user.getAge(), user.getId());
        return i;
    }

    @Override
    public int deleteUserById(Integer id) {

        String sql = "delete from user where id=?";

        int i = deleteById(sql, id);
        return i;
    }
}
